#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#if defined __MINGW_H
#error "stdlib cant compatile with mingw"
#endif

#define _PI(type,name,par) type __##name par
extern char **environ;

_PI(char *,getenv,(const char *name)){
	char **e=environ;
	char *str=NULL;
	size_t len=strlen(name);
	while(*e){
		if(!strncmp(name,*e,len)) {str=*e;break;}
		e++;
	}
	char *ret=malloc(strlen(str));
	char *target=strchr(str,'=');
	strcpy(ret,target);
	return ret;
}
static int power(char base,int p){
	int n=1,r=1;
	while(r<=p){
		n*=base;
		r++;
	}
	return n;
}
_PI(int,atoi,(const char *string)){
	char ch=0,num=0;
	char sign=-1;
	if(*string=='-') {sign=1;string++;}
	else sign=0;
	int len=strlen(string);
	int ret=0;
	while(*string){
		ch=*string;
		num=ch-0x30;
		ret+=power(num,len--);
		string++;
	}
	if(sign==1) ret=-ret;
	return ret;
}

_PI(int ,atexit,(void (*fp)(void))){
	fp();
	exit(0);
	return 0;
}
#if 0
_PI(int ,system,(const char *cmd)){
	pid_t pid=0;
	char *name=firstword(cmd);
	char *path=which(name);
	int argc=countword(cmd);
	char **argv=str2array(cmd,' ');
	int status=0;
	pid=fork();
	if(pid==0) status=execve(path,argv,NULL);
	if(pid<0) return pid;
	return 0;
}
#endif
_PI(void ,qsort,
(void *hear,size_t size,size_t a,int (*f)(const void *a,const void *b))){
		
}
#if defined MAIN
int main(){
	char *str="phamthechung0@gmail.com";
	void *vp=(void*)str;
	qsort(vp,strlen(str),5,cmp);
	printf(str);
}
#endif

